import os
from launch import LaunchDescription
from launch_ros.actions import Node
from ament_index_python.packages import get_package_share_directory

def generate_launch_description():
   # 定义SLAM参数
   slam_params = {
    "use_sim_time" : True,  # 使用仿真时间
    "base_frame"  :  "base_footprint",  # 基础坐标系
    "odom_frame"  :  "odom",  # 里程计坐标系
    "map_frame"   :  "map"  # 地图坐标系
   }
   # 创建SLAM节点
   slam_cmd = Node(
    package = "slam_toolbox",
    executable = "sync_slam_toolbox_node",
    parameters = [slam_params]
   )

   # 获取rviz文件路径
   rviz_file = os.path.join(get_package_share_directory('wpr_simulation2'), 'rviz', 'slam.rviz')
   # 创建rviz节点
   rviz_cmd = Node(
    package = 'rviz2',
    executable = 'rviz2',
    name = 'rviz2',
    arguments = ['-d',rviz_file]
   )

   # 返回启动描述
   return LaunchDescription([
    slam_cmd,
    rviz_cmd
   ])